public class Partition1 {
    public ListNode partition(ListNode pHead, int x) {
        // write code here
        ListNode flow = pHead;
        ListNode fast = pHead;
        int count = 0;
        while(fast != null&&fast.next != null) {
            fast = fast.next.next;
            flow = flow.next;
            count++;
        }
        if(x > count) {
            while(count != x){
                count++;
                flow = flow.next;
            }
            ListNode newPhead = flow.next;
            flow.next = null;
            flow = newPhead;
            while(flow.next != null) {
                flow = flow.next;
            }
            flow.next = pHead;
            return newPhead;
        }
        return pHead;
    }
}